﻿using ZR.Model.Souvenir;
using ZR.Model.Souvenir.Dto;
using ZR.Service.Souvenir.IService;

namespace ZR.Admin.WebApi.Controllers.Souvenir
{
    [Route(("souvenir/cart"))]
    public class CartController : BaseController
    {
        private readonly ICartService _cartService;

        public CartController(ICartService cartService)
        {
            _cartService = cartService;
        }
        
        [HttpPost("addCart")]
        public async Task<IActionResult> AddCart([FromBody] Cart cart)
        {
            return SUCCESS(await _cartService.InsertCartAsync(cart) > 0);
        }

        [HttpPut("updateCart")]
        public async Task<IActionResult> UpdateCart([FromBody] Cart cart)
        {
            return SUCCESS(await _cartService.UpdateCartAsync(cart) > 0);
        }
        
        [HttpDelete("deleteCart/{cartId}")]
        public async Task<IActionResult> DeleteCart(int cartId)
        {
            return SUCCESS(await _cartService.DeleteCartAsync(cartId) > 0);
        }
        
        [HttpPost("getCartWithPage")]
        public async Task<IActionResult> GetCartWithPage([FromBody] CartQueryDto cartQueryDto)
        {
            return SUCCESS(await _cartService.SelectCartWithPageAsync(cartQueryDto));
        }
        
        [HttpGet("getCartById/{cartId}")]
        public async Task<IActionResult> GetCartById(int cartId)
        {
            return SUCCESS(await _cartService.SelectCartAsyncById(cartId));
        }
    }
}